<template>
  <div class="layout">
    <div style="display: flex; justify-content: center">
      <div id="selectTypeDiv">
        <div
          :class="selectTypeIndex == 0 ? 'selectType btn' : 'btn'"
          @click="selectTypeIndex = 0"
        >
          线上/线下培训
        </div>
        <div
          :class="selectTypeIndex == 1 ? 'selectType btn' : 'btn'"
          @click="selectTypeIndex = 1"
        >
          在线课程
        </div>
      </div>
    </div>
    <!--线上/线下培训-->
    <div class="listDiv" v-show="selectTypeIndex == 0">
      <div class="tableDiv">
        <el-table
          :data="trainingList"
          border
          :highlight-current-row="false"
          style="width: 100%"
          header-cell-class-name="table-header"
        >
          <el-table-column
            prop="title"
            label="培训名称"
            min-width="100"
          ></el-table-column>
          <el-table-column
            prop="trainBeginTime"
            label="培训时间"
            min-width="160"
          >
            <template slot-scope="scope">
              {{ scope.row.trainBeginTime }} 至
              {{ scope.row.trainEndTime }}
            </template>
          </el-table-column>
          <el-table-column prop="typeName" label="类型" width="60">
          </el-table-column>
          <el-table-column prop="modeName" label="培训方式"> </el-table-column>
          <el-table-column prop="address" label="培训地址"> </el-table-column>
          <el-table-column prop="status" label="状态" width="65">
            <template slot-scope="scope">
              {{ scope.row.status == 1 ? "已报名" : "" }}
            </template>
          </el-table-column>
          <el-table-column
            prop="isJoin"
            align="center"
            label="是否参加"
            width="78"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.isJoin == 1" style="color: #6ac56e"
                >是</span
              >
              <span v-if="scope.row.isJoin == 0" style="color: #dc4040"
                >否</span
              >
              <span v-if="scope.row.isJoin == null" style="color: #666">-</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" width="100">
            <template slot-scope="scope">
              <el-button type="text" @click="linkDetail(scope.row.id)"
                >查看</el-button
              >
              <el-button
                type="text"
                @click="toSignUp(scope.row.id)"
                v-show="scope.row.isJoin == 1"
              >
                反馈
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div id="Pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageSize"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <!--在线课程-->
    <div class="listDiv" v-show="selectTypeIndex == 1">
      <div class="videoBox">
        <VideoFrame
          class="videoFrame"
          v-for="video in myOnlineList"
          :video="video"
          :key="video.id"
          :url="'comOnlineTrainDetail'"
          :showBtn="false"
        />
        <div v-show="myOnlineList.length % 3 == 2" class="virtualDom"></div>
      </div>
      <div id="Pagination" v-show="myOnlineList.length > 0">
        <el-pagination
          @size-change="handleSizeChangeVideo"
          @current-change="handleCurrentChangeVideo"
          :current-page="pageNumVideo"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageSizeVideo"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalVideo"
        >
        </el-pagination>
      </div>
    </div>
    <!-- 反馈弹出层 -->
    <feedbackDialog ref="DialogRef" :id="id" @refresh="successBack" />
  </div>
</template>

<script>
import VideoFrame from "@/components/videoFrame";
import feedbackDialog from "./feedbackDialog";
// api
import { getTrainingList, getOnlineCourseList } from "@/common/api/company.js";
export default {
  name: "companyMyTraining", //我的培训
  components: { VideoFrame, feedbackDialog },
  data() {
    return {
      id: null,
      selectTypeIndex: 0,
      pageNum: 1,
      pageSize: 10,
      total: null,
      pageNumVideo: 1,
      pageSizeVideo: 9,
      totalVideo: null,
      trainingList: [],
      myOnlineList: [], //在线课程列表
    };
  },
  mounted() {
    this.getTrainingList();
    this.getOnlineCourseList();
  },
  activated() {
    this.getTrainingList();
    this.getOnlineCourseList();
  },
  methods: {
    successBack(id) {
      let data = this.trainingList.find((e) => e.id == id);
      data.feedback = "有值了";
    },
    // 点击反馈按钮
    async toSignUp(id) {
      this.id = id;
      this.$refs.DialogRef.dialogVisible = true;
    },
    // 查看培训详情页
    linkDetail(id) {
      this.$router
        .push({ path: "comMyTrainingDetail", query: { id } })
        .catch((err) => err);
    },
    // 获取培训列表
    async getTrainingList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      };
      const { code, msg, rows, total } = await getTrainingList(params);
      if (code != "200") return this.$message.warning(msg);
      this.trainingList = rows;
      this.total = total;
    },
    // 获取在线课程列表
    async getOnlineCourseList() {
      let params = {
        pageNum: this.pageNumVideo,
        pageSize: this.pageSizeVideo,
      };
      const { code, msg, rows, total } = await getOnlineCourseList(params);
      if (code != "200") return this.$message.warning(msg);
      this.myOnlineList = rows;
      this.totalVideo = total;
    },
    // 改变培训通知每页大小
    handleSizeChange(e) {
      this.pageSize = e;
      this.getTrainingList();
    },
    // 改变培训通知当前页
    handleCurrentChange(e) {
      this.pageNum = e;
      this.getTrainingList();
    },
    // 改变在线课程每页大小
    handleSizeChangeVideo(e) {
      this.pageSizeVideo = e;
      this.getOnlineCourseList();
    },
    // 改变在线课程当前页
    handleCurrentChangeVideo(e) {
      this.pageNumVideo = e;
      this.getOnlineCourseList();
    },
  },
};
</script>

<style scoped>
.layout {
  min-height: 100vh;
  position: relative;
  padding-bottom: 150px;
  box-sizing: border-box;
}

.breadcrumb {
  width: 1000px;
  margin-bottom: 20px;
}

#wrapperDiv {
  text-align: left;
  width: 1000px;
  margin: 0 auto;
  padding: 20px 0;
}

.roomDiv {
  display: flex;
  justify-content: center;
}

.roomDiv .leftDiv {
  min-width: 200px;
  text-align: left;
}

.roomDiv .rightDiv {
  width: 800px;
  margin-left: 30px;
}

#selectTypeDiv {
  width: 1000px;
  display: flex;
  border-bottom: 3px solid #d00000;
  padding: 0 20px;
  /* margin-bottom: 30px; */
  margin-bottom: 20px;
}

#selectTypeDiv div {
  padding: 5px 20px;
  font-weight: bold;
  margin-bottom: -1px;
}

#selectTypeDiv .selectType {
  background-color: #d00000;
  color: #ffffff;
}

#selectTypeDiv .btn:hover {
  background-color: #d00000;
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease 0s;
}

/* 表格样式 */
#wrapperDiv .listDiv .tableDiv {
  /* margin: 18px 0; */
  margin: 5px 0 18px 0;
  /* border: 1px solid #eeeeee; */
  color: #666666;
  font-size: 12px;
}

#wrapperDiv .listDiv .tableDiv >>> .table-header {
  background: #f4f4f4 !important;
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

>>> .el-table tbody tr:hover > td {
  background-color: #ffffff !important;
}

#wrapperDiv .listDiv .tableDiv >>> .el-button--text {
  text-decoration: underline;
  color: #448dda;
}

.listDiv #Pagination {
  text-align: right;
  margin: 20px 0 30px 0;
}

.listDiv .videoBox {
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.listDiv .videoFrame {
  width: 245px;
  margin-bottom: 20px;
}

.listDiv .videoFrame:hover {
  cursor: pointer;
}

.listDiv .virtualDom {
  width: 245px;
  margin-bottom: 20px;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}
</style>